package jianzhi

import "fmt"

func twoSum(nums []int, target int) []int {
	m := map[int]int{}

	for _, v := range nums {
		if _, ok := m[target-v]; ok {
			return []int{v, target - v}
		} else if !ok {
			m[v] = target - v
		}
	}
	return []int{}

}

func TwoSum2(nums []int, target int) []int {

	left := 0
	right := len(nums) - 1

	for left < right {
		if (nums[left] + nums[right]) == target {
			return []int{nums[left], nums[right]}
		} else if target < (nums[left] + nums[right]) {
			fmt.Println(target, ">", nums[left]+nums[right])
			right--
		} else {
			fmt.Println(target, "<", nums[left]+nums[right])
			left++
		}
	}

	return []int{}

}
